using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace PicAFlick.App
{
    public partial class ImageNavigator : UserControl
    {
        public ImageNavigator()
        {
            InitializeComponent();
           
        }
        private ImageViewForm _imageViewForm;

        public ImageViewForm ImageViewForm
        {
            get { return _imageViewForm; }
            set
            {
                if (value != null)
                {
                    _imageViewForm = value;
                    this.pictureBox1.Image = new System.Drawing.Bitmap(ImageViewForm.ImageDetails.VirtualImage.RealImage, new System.Drawing.Size(100, 100));
                }
            }
        }

       

        private void ThumbNavigate(object sender, EventArgs e)
        {
            int x = ((MouseEventArgs)e).X;
            int y = ((MouseEventArgs)e).Y;
            if (x > 0 && y > 0)
            {
                int newV = (int)((ImageViewForm.ImageDetails.VirtualImage.RealImage.Height / 100) * y * ImageViewForm.ImageDetails.VirtualImage.ZoomLevel);
                int newH = (int)((ImageViewForm.ImageDetails.VirtualImage.RealImage.Width / 100) * x * ImageViewForm.ImageDetails.VirtualImage.ZoomLevel);

                this.ImageViewForm.ImageDetails.VirtualImage.ViewPortCentre = new Point(newH, newV);
                


            }
        }

 

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ThumbNavigate(sender, e);
            }
        }

        private void trackBar1_valueChanged(object sender, EventArgs e)
        {
            decimal scaleFactor = 1;
            if (trackBar1.Value < 5)
            {
                scaleFactor = 1.0m / (5 - trackBar1.Value);

            }
            else if (this.trackBar1.Value > 5)
            {
                scaleFactor = trackBar1.Value - 5;
            }

            ImageViewForm.ImageDetails.VirtualImage.ZoomLevel = scaleFactor;
        }

        

       

        
     
    }
    
}
